package org.feng.api;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;

/**
 * 结果vo
 *
 * @author feng
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
@ApiModel("响应结果VO")
public class ResultVo<T> implements Serializable {

    @Serial
    private static final long serialVersionUID = 2351036227977338319L;

    @ApiModelProperty(name = "code", value = "响应码")
    private Integer code;

    @ApiModelProperty(name = "message", value = "错误信息")
    private String message;

    @ApiModelProperty(name = "data", value = "响应数据")
    private T data;

    @ApiModelProperty(name = "timestamp", value = "时间戳")
    private Long timestamp;

    public ResultVo(int code, String message, T data) {
        this(code, message, data, System.currentTimeMillis());
    }


    public boolean requestSuccess() {
        return Objects.equals(0, code);
    }
}
